package com.msy.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @date 2020/11/16 - 20:49
 * 拦截器
 */

public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute("LoginUser");
        if (loginUser == null) {
            request.setAttribute("msg", "权限不够，请先登录");
            request.getRequestDispatcher("/index.html").forward(request, response);
            return false;

        } else {
            return true;
        }
    }
}
